package com.meilai.project.controller.web.market.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meilai.project.controller.web.market.dto.BillMarketListDTO;
import com.meilai.project.controller.web.market.entity.BillMarket;
import com.meilai.project.controller.web.market.vo.BillMarketForADMakeVO;
import com.meilai.project.controller.web.market.vo.BillMarketVO;
import com.meilai.project.controller.web.market.vo.MarketBillVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 市场单 Mapper 接口
 * </p>
 *
 * @author xchen
 * @since 2022-07-16
 */
@Mapper
public interface BillMarketMapper extends BaseMapper<BillMarket> {
    List<BillMarketForADMakeVO> listForADMakeByContractId(
            @Param("contractId") Long contractId);

    List<BillMarketForADMakeVO> listForADMakeByCustomerId(
            @Param("customerId") Long customerId);

    BillMarketVO queryDetailById(@Param("id") Long id);

    List<BillMarketVO> selectPageList(Page<BillMarketVO> page,
                                        @Param("query") BillMarketListDTO dto);

    @Update("update bill_market set contract_id = #{newContractId} where contract_id = #{oldContractId}")
    void updateContractId(@Param("oldContractId") Long oldContractId, @Param("newContractId") Long newContractId);

    @Update("update bill_market set bill_sale_id = #{newSaleId} where bill_sale_id = #{oldSaleId}")
    void updateSaleId(@Param("oldSaleId") Long oldSaleId, @Param("newSaleId") Long newSaleId);

    MarketBillVO querySingleById(@Param("id") Long id);

    MarketBillVO querySubByDetailId(@Param("marketDetailId") Long marketDetailId);

    List<MarketBillVO> queryPageList(Page<MarketBillVO> page,
                                      @Param("query") BillMarketListDTO dto);
}
